package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Kernel.Namespace;
import edu.pku.sei.modeler.model.uml.Kernel.PackageImport;
import edu.pku.sei.modeler.model.uml.Kernel.UMLPackage;
import edu.pku.sei.modeler.uml.commands.ConnectionModelDeleteCommand;

public class UMLPackageImportDeleteCommand extends ConnectionModelDeleteCommand {

	public UMLPackageImportDeleteCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel, MetaModelElement targetModel) {
		super(connectionModel, sourceModel, targetModel);
	}

	@Override
	public boolean canExecute() {
		if (this.sourceModel instanceof Namespace) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void execute() {
		PackageImport packageImport = (PackageImport) this.connectionModel;
		Namespace sourceNamespace = (Namespace) this.sourceModel;
		UMLPackage targetPackage = (UMLPackage) this.targetModel;

		packageImport.getImportedPackage().remove(targetPackage);
		sourceNamespace.getPackageImport().remove(packageImport);
	}

	@Override
	public void undo() {
		PackageImport packageImport = (PackageImport) this.connectionModel;
		Namespace sourceNamespace = (Namespace) this.sourceModel;
		UMLPackage targetPackage = (UMLPackage) this.targetModel;

		packageImport.getImportedPackage().add(targetPackage);
		sourceNamespace.getPackageImport().add(packageImport);

	}

}
